﻿using SovaDataService.SoModels;
using SovaDataService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SovaDataService.SoDataServices
{
    public class TagDataService
    {
        /**
         * Retrieves all tags from the database.
         */
        public IEnumerable<Tag> GetAll()
        {
            using (var db = new DbContext())
            {
                IQueryable<Tag> tags = db.Tags
                    .OrderBy(au => au.Id);
                return tags.ToList();
            }
        }

        /**
         * Retrieves one tag with the given id from the database.
         */
        public Tag GetOne(int id)
        {
            using (var db = new DbContext())
            {
                IQueryable<Tag> tag = db.Tags
                    .Where(q => q.Id == id);
                return tag.SingleOrDefault();
            }
        }

        /**
         * Retrieves the total without having to fetch all the tags from db.
         */
        public int GetCount()
        {
            using (var db = new DbContext())
            {
                return db.Tags.Count();
            }
        }
    }
}
